package com.example.medicalrecord.AggregationModule.doctor.service.impl;


import com.example.medicalrecord.AggregationModule.doctor.mapper.DoctorMapper;
import com.example.medicalrecord.AggregationModule.doctor.pojo.dto.DoctorQuery;
import com.example.medicalrecord.AggregationModule.doctor.pojo.dto.PatientQuery;
import com.example.medicalrecord.AggregationModule.doctor.pojo.entity.MedicalTreatment;
import com.example.medicalrecord.AggregationModule.doctor.pojo.vo.DoctorVO;
import com.example.medicalrecord.AggregationModule.doctor.service.DoctorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    DoctorMapper doctorMapper;

    @Override
    public List<DoctorVO> selectPatient(PatientQuery patientQuery) {
       log.debug("查询患者业务：patientQuery={}",patientQuery);
       List<DoctorVO> list =doctorMapper.selectPatient(patientQuery);
       return list;
    }

    @Override
    public void savePatient(DoctorQuery doctorQuery) {
        log.debug("保存患者业务：doctorQuery={}",doctorQuery);
        MedicalTreatment medicalTreatment = new MedicalTreatment();
        BeanUtils.copyProperties(doctorQuery,medicalTreatment);
        if (medicalTreatment.getId() == null) {
            // 诊断病历
            medicalTreatment.setCreateTime(new Date());
            doctorMapper.insert(medicalTreatment);
        }else {
            // 修改诊断病历
            medicalTreatment.setUpdateTime(new Date());
            doctorMapper.update(medicalTreatment);
        }
    }
}
